package org.test;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserServlet extends HttpServlet {
  //Process the HTTP Get request
	public void doGet(HttpServletRequest request,HttpServletResponse response) throws 
	   ServletException,IOException{
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out=response.getWriter();
		request.setCharacterEncoding("UTF-8");
		out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
	    out.println("<html>");
	    out.println("<head><title>A servlet</title></head>");
	    out.println("<head><link rel='Stylesheet' href='"+request.getContextPath()+"/css/style.css' type='text/css'></head>");
	    out.println("<body  style='background-color: #1a4e88'");
        out.println("<div class='index_img' align='center'><h1><font size='20' color='#fff' >         智能在线聊天室</font></h1></div>");
	    out.println("<div class='center'>");
	    out.println(" <div class='form-box' style='width: 500px;position:relative;margin: 0 auto;margin-left:100px;height: 350px'>");
        out.println("<div style='width:450px;margin:0 auto;position: relative;border: hidden; border-radius: 15px'>");
	    ServletContext context=getServletContext();
	    //判断用户列表存在
	    if(context.getAttribute("userlist")==null){
	    	Vector aduser=new Vector();
	    	context.setAttribute("userlist",aduser);
	    }
	    //判断信息列表存在
	    if(context.getAttribute("messagelist")==null){
	    	Vector message=new Vector();
	    	context.setAttribute("messagelist",message);
	    }
	    out.println("<form method='post' action='/MyChat/loginDeal.jsp'>");
	    out.println("<input type='text' name='username'  placeholder='请输入用户名' autocomplete='off' autofocus='autofocus' required='required' autocomplete='off'   autofocus='autofocus' required='required' style='border-radius: 15px;height: 45px;text-align: center;border: hidden;font-size: 25px'/>");
	    out.println("<input type='password' name='password' placeholder='请输入密码' required='required'  style='height: 45px;text-align: center;border: hidden;font-size:25px;border-radius: 15px'/>");
	    out.println("<button type='submit'>登录</button>");
	    out.println(" <div style='position: absolute;top: -45px;left: 0' class='error text-center'>");
        out.println("<?= $err_message ?></div>");
	    out.println("</form>");
	    out.println("</div>");
	    out.println("<span style='margin-left:10px'><font color='#fff' size='6px'><a href='/MyChat/retrievePassword.jsp'>找回密码</a></font></span>");
	    out.println("<span style='margin-left:200px'><font color='#fff' size='6px'><a href='/MyChat/register.jsp'>立即注册</a></font></span>");
	    out.println("</div></div>");
	    out.println("</body>");
	    out.println("</html>");
	    out.close();
	}
	//Process the HTTP post request
	  public void doPost(HttpServletRequest request,HttpServletResponse response)throws
	   IOException,ServletException{
		  doGet(request,response);
	  }
}
